package util
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	public class EffectShowCard extends EventDispatcher
	{
		public var count:uint = 0;
		public var reatd:uint = 0;
		public var timer:Timer;
		public var cards:Array;
		public static const SHOW_CARD:String = "show_card";
		
		public function EffectShowCard(delay:uint)
		{
			timer = new Timer(delay);
			timer.addEventListener(TimerEvent.TIMER, onTimer);
		}
		public function setCard(cards1:Array):void
		{
			cards = cards1;
			reatd = cards1.length;
			for(var i:uint = 0; i < cards.length; i++)
				(cards[i] as DisplayObject).visible = false;
		}
		public function start():void
		{
			reset();
			timer.start();
		}
		
		public function reset():void
		{
			count = 0;
		}
		
		public function stop():void
		{
			timer.stop();
		}
		
		private function onTimer(evt:TimerEvent):void
		{
			if(count >= reatd)
			{
				dispatchEvent(new Event(Event.COMPLETE));
				timer.stop();
				return ;
			}
			(cards[count] as DisplayObject).visible = true;
			this.dispatchEvent(new Event(SHOW_CARD));
			count++;
		}
	}
}